#include<bits/stdc++.h>

using namespace std;

typedef struct LNode {
    int data;
    struct LNode *next;
}LNode, *LinkedList;

bool Init(LinkedList &L) {
    L = (LNode*)malloc(sizeof(LNode));
    L->next = NULL;
    if (L == NULL)
        return false;
    return true;
}

bool Insert(LinkedList &L, int a) {
    LNode *p = L;
    LNode *s = (LNode*)malloc(sizeof(LNode));
    if (s == NULL)
        return false;
    s->data = a;
    while (p->next != NULL)
        p = p->next;
    p->next = s;
    s->next = NULL;
    return true;
}

void PrintList(LinkedList L) {
    LNode *p = L;
    while (p->next != NULL) {
        p = p->next;
        if (p->next == NULL)
            cout << p->data;
        else
            cout << p->data << "->";
    }
    cout << endl;
}

void func(LinkedList &L, int n) {
    int table[n + 1];
    memset(table, 0, sizeof(int) * (n + 1));
    LNode *p = L->next;
    LNode *pre = L;
    while (p != NULL) {
        if (table[abs(p->data)] == 0) {
            table[abs(p->data)] = 1;
            p = p->next;
            pre = pre->next;
        } else {
            LNode *q = p;
            pre->next = q->next;
            p = p->next;
            free(q);
        }
    }
}

int main() {
    // 测试
    int n = 100;
    int num[] = {21, -15, -15, -7, 15};
    LinkedList L;
    Init(L);
    for (int i = 0; i < 5; i++)
        Insert(L, num[i]);
    cout << "Input:" << endl;
    PrintList(L);
    func(L, n);
    cout << "Result:" << endl;
    PrintList(L);
    return 0;
}